package com.alu.sg.allstart.allstar.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alu.sg.allstart.R;
import com.alu.sg.allstart.allstar.bean.NamesData;

import java.util.List;

/**
 * Created by Alu on 2017/9/14.
 * version 1.0
 *
 */

class MyAdapter2 extends RecyclerView.Adapter<MyAdapter2.ViewHolder> {
    private Context context;
    private List<NamesData> list;

    MyAdapter2(Context context, List<NamesData> strings) {
        this.context = context;
        this.list = strings;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_my_decoration, parent,
                false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText(list.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

        ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.tv_name);
        }
    }

    public int getLetterPosition(String letter) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getPys().substring(0,1).equals(letter)) {
                return i;
            }
        }
        return -1;
    }
}
